package com.example.easybuy.aop;

import com.example.easybuy.mappers.ProductMapper;
import com.example.easybuy.repository.ProductEsRepository;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;

//@Component
//@Aspect
//public class MyAop {
//    @Autowired
//    private ProductEsRepository repository;
//    @Autowired
//    private ProductMapper productMapper;
//
//    // 定义一个切点，匹配ProductController类中的所有方法
//    @Pointcut("execution(* com.example.easybuy.controller.ProductController.*(..))")
//    public void productControllerMethods() {
//    }
//
//    // 环绕增强，但不包括byPage方法
//    @Around("productControllerMethods() && !execution(* com.example.easybuy.controller.ProductController.byPage(..)) &&!execution(* com.example.easybuy.controller.ProductController.getPro(..))")
//    public Object aroundAdvice(ProceedingJoinPoint joinPoint) throws Throwable {
//        System.out.println("前置增强");
//
//        Object result = joinPoint.proceed();
//        repository.deleteAll();
//        repository.saveAll(productMapper.byPage(new HashMap<>()));
//        System.out.println("后置增强");
//
//        return result;
//    }
//}
